#include "PointEmitter.h"
#include "ParticleFlyweight.h"

CPointEmitter::CPointEmitter(void)
{
}


CPointEmitter::~CPointEmitter(void)
{
}

void CPointEmitter::SpawnParticles(int maxParticles,
							  float minPosX, float maxPosX, float minPosY, float maxPosY)
{
	//if( maxParticles > 0)
	//	for(int i = 0; i <= maxParticles; ++i)
	//	{
	//		float Life =(float)(rand()%((int)m_pFLW->MaxLife() - (int)m_pFLW->MinLife())+(int)m_pFLW->MinLife());

	//		m_LiveParticles.push_back(CParticle(Life, minPosX, minPosY,m_pFLW));
	//	}


		if( maxParticles > 0)
			for(int i = 0; i <= maxParticles; ++i)
			{
				//float Life =(float)(rand()%((int)m_pFLW->MaxLife() - (int)m_pFLW->MinLife())+(int)m_pFLW->MinLife());
				float Life = CalcLifetime();

				//float posX, posY;
				//CalcEmitRange( minPosX, maxPosX, minPosY, maxPosY, posX, posY);

				if(m_DeadParticles.size() == 0)
				{
					m_LiveParticles.push_back(CParticle(Life, minPosX, minPosY,m_pFLW));
				}
				else if(m_DeadParticles.size() > 0 && m_bIsLooping == true)
				{
					CParticle temp = *(m_DeadParticles.begin());
					m_DeadParticles.pop_front();
					temp.InitializeParticle(Life, minPosX, minPosY,m_pFLW);
					m_LiveParticles.push_back(temp);
				}
			}
}